package com.lemon.smartsafetynew.ui.activity.hidden;

import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;

import com.lemon.smartsafety.R;
import com.lemon.smartsafety.app.AppManager;
import com.lemon.smartsafetynew.entity.common.CommonBo;
import com.lemon.smartsafetynew.ui.activity.base.SwipeBackActivity;
import com.lemon.smartsafetynew.ui.fragment.record.CompanyListFragment;
import com.lemon.smartsafetynew.ui.fragment.record.GridListFragment;

import butterknife.Bind;

public class SafeHiddenDangerSearchActivity extends SwipeBackActivity {

    @Bind(R.id.tabLayout)
    TabLayout tabLayout;
    @Bind(R.id.viewPager)
    ViewPager viewPager;

    private static final int TAB_SIZE = 2;

    @Override
    protected void initTitle() {
        this.setBarTitle("搜索");
    }

    @Override
    protected void callFinish() {
        AppManager.getAppManager().finishActivity(SafeHiddenDangerSearchActivity.this);
    }

    @Override
    protected int getContentViewId() {
        return R.layout.activity_viewpage_tab_layout;
    }

    @Override
    protected void initViews() {
        super.initViews();
        tabLayout.post(new Runnable() {
            @Override
            public void run() {
                setIndicator(tabLayout, 20, 20);
            }
        });

        viewPager.setAdapter(new SafeHiddenSearchViewpagerAdapter(getSupportFragmentManager()));
        tabLayout.setupWithViewPager(viewPager);
    }

    private class SafeHiddenSearchViewpagerAdapter extends FragmentStatePagerAdapter {

        public SafeHiddenSearchViewpagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            switch (position) {
                case 0:
                    return GridListFragment.newInstance(CommonBo.BusinessType.HIDDEN_JUMP_SEARCH.getValue());
                case 1:
                    return CompanyListFragment.newInstance(CommonBo.BusinessType.HIDDEN_JUMP_SEARCH.getValue());
                default:
                    return GridListFragment.newInstance(CommonBo.BusinessType.HIDDEN_JUMP_SEARCH.getValue());
            }
        }

        @Override
        public int getCount() {
            return TAB_SIZE;
        }

        @Override
        public CharSequence getPageTitle(int position) {
            switch (position) {
                case 0:
                    return getString(R.string.use_grid);
                case 1:
                    return getString(R.string.use_company);
                default:
                    return "";
            }
        }

    }

}
